#include "Button.h"
#include "SDL_Init.h"

Button::Button( int x, int y, int w, int h )
{
    //Set the button's attributes
    box.x = x;
    box.y = y;
    box.w = w;
    box.h = h;

	MOUSE_OVER = false;
	MOUSE_DOWN = false;

    ////Set the default sprite
    //clip = &clips[ CLIP_MOUSEOUT ];
}
void Button::handle_seEvents(SDL_Event* seEvent)
{
    //The mouse offsets
    int x = 0, y = 0;

    //If the mouse moved
    if( seEvent->type == SDL_MOUSEMOTION )
    {
        //Get the mouse offsets
        x = seEvent->motion.x;
        y = seEvent->motion.y;

        //If the mouse is over the button
        if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
        {
            //Set the button sprite
            MOUSE_OVER = true;
        }
        //If not
        else
        {
            //Set the button sprite
			MOUSE_OVER = false;
        }
    }
    //If a mouse button was pressed
    if( seEvent->type == SDL_MOUSEBUTTONDOWN )
    {
        //If the left mouse button was pressed
        if( seEvent->button.button == SDL_BUTTON_LEFT )
        {
            //Get the mouse offsets
            x = seEvent->button.x;
            y = seEvent->button.y;

            //If the mouse is over the button
            if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
            {
                //Set the button sprite
                MOUSE_DOWN = true;
           }
        }
    }
    //If a mouse button was released
    if( seEvent->type == SDL_MOUSEBUTTONUP )
    {
        //If the left mouse button was released
        if( seEvent->button.button == SDL_BUTTON_LEFT )
        {
            //Get the mouse offsets
            x = seEvent->button.x;
            y = seEvent->button.y;

            //If the mouse is over the button
            if( ( x > box.x ) && ( x < box.x + box.w ) && ( y > box.y ) && ( y < box.y + box.h ) )
            {
                //Set the button sprite
                MOUSE_DOWN = false;
            }
        }
    }
}
void Button::show(SDL_Surface* screen)
{
    //Show the button
    draw_tile(screen, buttondisplay, &box);
	//SDL_FillRect(screen, &box, 0x0000ff);

	//if (MOUSE_DOWN)
	//{
	//}
}

bool Button::load_buttonimage(char* image)
{
	buttondisplay = load_image(image, NULL);
	if (buttondisplay == NULL)
	{
		return false;
	}
	box.w = buttondisplay->w;
	box.h = buttondisplay->h;

	return true;
}